package com.rambo.androidnews.itemprovider;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rambo.androidnews.ResourceTable;
import com.rambo.baselib.model.wanad.WanAdApiArticle;
import com.rambo.baselib.provider.BaseViewHolder;
import com.rambo.baselib.provider.ListItemProvider;
import ohos.agp.components.Image;
import ohos.app.Context;

import java.util.List;

/***********************************************************************
 * <p>@description:项目内容
 * <p>@author: rambo
 * <p>@version: 1.0.0
 * <p>@created on: 2022/1/13 16:57
 **********************************************************************/
public class ProjectItemProvider extends ListItemProvider<WanAdApiArticle, BaseViewHolder> {
    public ProjectItemProvider(Context context, List<WanAdApiArticle> data) {
        super(context, ResourceTable.Layout_componet_project_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, WanAdApiArticle item, int position) {
        helper.setText(ResourceTable.Id_tv_title, item.getTitle())
                .setText(ResourceTable.Id_tv_author, "作者：" + item.getAuthor())
                .setText(ResourceTable.Id_tv_time, "发布时间：" + item.getPublishTime());
        Image image = helper.getView(ResourceTable.Id_image);
        if (item.getEnvelopePic() == null) {
            image.setPixelMap(ResourceTable.Graphic_background_ability_main);
        } else {
            if (item.getEnvelopePic().endsWith(".gif")) {
                Glide.with(context)
                        .asGif()
                        .diskCacheStrategy(DiskCacheStrategy.NONE)
                        .skipMemoryCache(false)
                        .load(item.getEnvelopePic())
                        .into(image);
            } else {
                Glide.with(context)
                        .asDrawableHarmony()
                        .diskCacheStrategy(DiskCacheStrategy.NONE)
                        .skipMemoryCache(false)
                        .load(item.getEnvelopePic())
                        .into(image);
            }
        }
    }
}
